vuex 的数据流 核心原理是什么
actions 更新 mutations,修改 state
核心,在每个组件中挂载 $store vue data 组件有 store 就是响应式
dispatch 匹配到 store 存放的 action 方法 commit 的时候匹配 mutations 方法
js
Vue.mixin({
beforeCreate() {
if (this.$options.store) {
this.$store = this.$options.store; // 根结点赋值
} else {
this.$store = this.$parent && this.$parent.$store; // 每个实例都会有父亲。故一层层给实例赋值
}
},
});